<?

//Data loading
$title='DAFTAR GIRO';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI TATANAN CONTAINER';

$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new GridPDFReport("P","mm","Letter");
$fromDate = GetParam("fromDate","");
$toDate  = GetParam("toDate","");
$pdf->AddPage();
$Result = GridList ();
if ($Result) $pdf->GridTable($Result);
$pdf->Output();

function GridList () {
    $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    list($day,$month,$year) = explode("/",GetParam("fromDate",""));
    $fromDate = date('Y-m-d',mktime(0,0,0,$month,$day,$year));
    list($day,$month,$year) = explode("/",GetParam("toDate",""));
    $toDate   = date('Y-m-d',mktime(0,0,0,$month,$day,$year));

    $wherenobkt = "(nobkt like 'ZTB%')";
	$SQL = "SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as trdate FROM ais_memorial_z WHERE ".$wherenobkt." AND ifnull(nocek,'')<>'' AND urut<>999";
	if (GetParam("office",""))
	$SQL .= " AND ktrasl= '".GetParam("office","")."'";

    if (GetParam("skada",""))
	$SQL .= " AND skada= '".GetParam("skada","")."'";

	$SQL .= " ORDER BY duedate, nobkt";        
	//print $SQL."<br><br>\n\n\n\n";die();
	$MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    return $MyResult;
}

class GridPDFReport extends PDF {
	function Header() {
		global $title,$perush,$page,$DEFINE_FONT;
		if ($DEFINE_FONT==0) {
			$this->AddFont('arialn','','arialn.php');
			$DEFINE_FONT=1;
		}
		//$this->SetLeftMargin(5);
		$FDATE = explode('/',GetParam("fromDate",""));
		$TDATE = explode('/',GetParam("toDate",""));

		$this->SetFont('arialn','',10);
    	$this->Cell(200,5,$perush,0,1,'C',0);
    	$this->Cell(200,5,$title,0,1,'C',0);
    	$this->Cell(200,5,"AS OF : ".date('d/m/Y',mktime(0,0,0,$TDATE[1],$TDATE[0],$TDATE[2])),0,1,'C',0);
		$this->SetLeftMargin(5);
    	$this->Cell(200,5,$page." ".$this->PageNo(),0,1,'R',0);
    	$this->Line(5,30,210,30);
    	$this->Ln();
    	$this->Ln();
	    //Header
	    //Column widths
	    $w=array(10,40,25,25,20,55,25);
	    //$this->SetFont('arialn','',10);
	    $this->Cell($w[0],7,"NO.",1,0,'C',0);
	    $this->Cell($w[1],7,"DEBNAM",1,0,'C',0);
	    $this->Cell($w[2],7,"NOMINAL",1,0,'C',0);
	    $this->Cell($w[3],7,"CHEQUE/BG NO.",1,0,'C',0);
	    $this->Cell($w[4],7,"DUEDATE",1,0,'C',0);
	    $this->Cell($w[5],7,"DESCRIPTION",1,0,'C',0);
	    $this->Cell($w[6],7,"REF NO.",1,0,'C',0);
	    $this->Ln();
	    $this->SetFont('arialn','',8);
	}

	function GridTable($Result) {
	    //Column widths
	    $w=array(10,40,25,25,20,55,25);
	    //Data
	    foreach($Result as $row)
	    {
		    $n++;
		    $this->Cell($w[0],6,$n,'LR',0,'R');
		    $this->Cell($w[1],6,(strlen($row["debnam"])>20)?substr($row["debnam"],0,20)."...":$row["debnam"],'LR',0,'L');
		    $this->Cell($w[2],6,FormatNumber($row["jumlah"]),'LR',0,'R');
		    $this->Cell($w[3],6,$row["nocek"],'LR',0,'L');
		    $this->Cell($w[4],6,$row["duedate"],'LR',0,'C');
		    $this->Cell($w[5],6,$row["uraian"],'LR',0,'L');
		    $this->Cell($w[6],6,$row["noref"],'LR',0,'L');
		    $this->Ln();
	    }

            /*
            $this->Cell($w[0],7,'','L',0,'R',0);
	    $this->Cell($w[1]+$w[2]+$w[3]+$w[4],7,"SALDO AKHIR: ",0,0,'R',0);
	    $this->Cell($w[5],7,number_format($total,2),1,0,'R',0);
	    $this->Cell($w[6],7,number_format($saldoakhir,2),1,0,'R',0);
	    $this->Ln();
*/
/*
	    $this->Cell($w[0],7,'','L',0,'R',0);
	    $this->Cell($w[1]+$w[2]+$w[3]+$w[4],7,"BALANCE: ",0,0,'R',0);
	    $this->Cell($w[5],7,number_format($saldoakhir,2),1,0,'R',0);
	    $this->Cell($w[6],7,number_format($total,2),1,0,'R',0);
	    $this->Ln();
*/
	    //Closure line
	    //$this->Cell(array_sum($w),0,'','T');
	}

	function Footer() {
	    //Closure line
	    $this->Cell(200,0,'','T');
	}

}


?>